*===============================================================================
* Do-file creates "Experimental Dataset: Violence Expectations, Mobile Money Balance and Cash Savings"
* Table 3
*===============================================================================
clear
set more off


cd "~/Dropbox/VFD/REStat_Native_Files/Stata_Files"
local output "~/Dropbox/VFD/REStat_Native_Files/Stata_Files/Output"

use cadg_master_NATIVE.dta, clear

*** PANEL A: Mobile Money Balance ***

* Running regression to get right e(sample)
qui:xi: reg cumbalance treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post i.ym if sample_cash_outlier==0, cl(employeenumber) 
gen sample=1 if e(sample)

* Column 1
reghdfe cumbalance treat_post treat_final post if sample_cash_outlier==0 & sample==1, ab(ym) cl(employeenumber) keepsing 
est store col1
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "NO"
estadd local individFE "NO"
estadd scalar adjR2 =  e(r2_a)
sum cumbalance if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)

* Column 2
reghdfe cumbalance treat_post treat_final post if sample_cash_outlier==0 & sample==1, ab(ym block_final) cl(employeenumber) keepsing 
est store col2
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "YES"
estadd local individFE "NO"
estadd scalar adjR2 = e(r2_a)
sum cumbalance if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Column 3
reghdfe cumbalance treat_post treat_final post if sample_cash_outlier==0 & sample==1, ab(ym employeenumber) cl(employeenumber) keepsing 
est store col3
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "-"
estadd local individFE "YES"
estadd scalar adjR2 = e(r2_a)
sum cumbalance if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Column 4
reghdfe cumbalance treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post if sample_cash_outlier==0, ab(ym) cl(employeenumber) keepsing 
est store col4
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "NO"
estadd local individFE "NO"
estadd scalar adjR2 = e(r2_a)
sum cumbalance if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Column 5
reghdfe cumbalance treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post if sample_cash_outlier==0, ab(ym block_final) cl(employeenumber) keepsing 
est store col5
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "YES"
estadd local individFE "NO"
estadd scalar adjR2 =  e(r2_a)
sum cumbalance if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Column 6
reghdfe cumbalance treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post if sample_cash_outlier==0, ab(ym employeenumber) cl(employeenumber) keepsing 
est store col6
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "-"
estadd local individFE "YES"
estadd scalar adjR2 =  e(r2_a)
sum cumbalance if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Export to Latex
esttab col1 col2 col3 col4 col5 col6 using "`output'/table_3a.tex", cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) ///
starlevels(* .1 ** .05 *** .01) style(tex) keep(treat_post violence_34 treat_post_v34) ///
stats(samplestr controlmean N_clust N adjR2 monthFE stratumFE individFE, fmt(0 2 0 0 2 0 0 0) label("Sample" "Control Mean Dep Var" "\# Employees" "\# Observations" "R-Squared" "Month FE" "Strata FE" "Employee FE")) ///
label title("Experimental Dataset: Violence Expectations, Mobile Money Balance and Cash Savings") replace


*** PANEL B: Cash Savings ***

* Running regression to get right e(sample)
qui: drop sample
qui: reghdfe cash_savings treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post if sample_cash_outlier==0, cl(employeenumber) ab(employeenumber ym) keepsing
gen sample=1 if e(sample)


* Column 1
reghdfe cash_savings treat_post treat_final post if sample_cash_outlier==0 & sample==1, ab(ym) cl(employeenumber) keepsing 
est store col1 
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "NO"
estadd local individFE "NO"
estadd scalar adjR2 =  e(r2_a)
sum cash_savings if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Column 2
reghdfe cash_savings treat_post treat_final post if sample_cash_outlier==0 & sample==1, ab(ym block_final) cl(employeenumber) keepsing
est store col2
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "YES"
estadd local individFE "NO"
estadd scalar adjR2 =  e(r2_a)
sum cash_savings if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Column 3
reghdfe cash_savings treat_post treat_final post if sample_cash_outlier==0 & sample==1, cl(employeenumber) ab(employeenumber ym) keepsing
est store col3
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "-"
estadd local individFE "YES"
estadd scalar adjR2 =  e(r2_a)
sum cash_savings if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Column 4
reghdfe cash_savings treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post if sample_cash_outlier==0, ab(ym) cl(employeenumber) keepsing
est store col4 
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "NO"
estadd local individFE "NO"
estadd scalar adjR2 =  e(r2_a)
sum cash_savings if treat_final==0 & e(sample)
estadd scalar controlmean = r(mean)

* Column 5
reghdfe cash_savings treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post if sample_cash_outlier==0, ab(ym block_final) cl(employeenumber) keepsing
est store col5
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "YES"
estadd local individFE "NO"
estadd scalar adjR2 =  e(r2_a)
sum cash_savings if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)

* Column 6
reghdfe cash_savings treat_post treat_post_v34 post_v34 treat_final t0_v34 violence_34 post if sample_cash_outlier==0, cl(employeenumber) ab(employeenumber ym) keepsing
est store col6
estadd local samplestr "All"
estadd local monthFE "YES"
estadd local stratumFE "-"
estadd local individFE "YES"
estadd scalar adjR2 =  e(r2_a)
sum cash_savings if treat_final==0  & e(sample)
estadd scalar controlmean = r(mean)


* Export to Latex
esttab col1 col2 col3 col4 col5 col6 using "`output'/table_3b.tex", cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) ///
starlevels(* .1 ** .05 *** .01) style(tex) keep(treat_post treat_post_v34 violence_34) ///
stats(samplestr controlmean N_clust N adjR2 monthFE stratumFE individFE, fmt(0 2 0 0 2 0 0 0)  label("Sample" "Control Mean Dep Var" "\# Employees" "\# Observations" "R-Squared" "Month FE" "Strata FE" "Employee FE")) ///
label title("Experimental Dataset: Violence Expectations, Mobile Money Balance and Cash Savings") replace 
